<style>
        #element_to_pop_up_{ 
            background-color:#fff;
            box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.298);
            border-radius:5px;
            color:#000;
            display:none; 
            padding:5px;
            min-width:800px;
            min-height: 500px;   
        }
        .b-close{
            cursor:pointer;
            position:absolute;
            right:10px;
            top:5px;            
        } 

    </style>
<div id="element_to_pop_up_">
        <a class="b-close">X</a>                    
        <div class="widget grid12">
            <div class="whead"><h6>CLIENTE</h6><div class="clear"></div></div>
              <div id="listaventas" style="overflow:scroll;height:500px;width:800px;">
              
              </div> 
        </div>
</div> 
<div class="widget">
    <div class="whead"><h6>LISTADO DE VENTAS</h6><div class="clear"></div></div>
    
    <div class="shownpars">
    <?php if(empty($cliente)):?>
    <div class="formRow">
    <?php
    echo $this->Form->create('Cliente', array('action' => 'ajaxlistado'));
   ?>
        <div class="grid3"><label>Cliente:<span class="req">*</span></label></div>
        <div class="grid3">
            <?php echo $this->Form->text('nombre', array('class'=>'validate[required] input-text', 'size'=>'40', 'id'=>'validate')); ?>
        </div>

        <div class="grid3">
        <?php
        echo $this->Js->submit('Buscar', array('url' => array('controller' => 'Ventasproductos','action' => 'ajaxlistado'), 
        'before' => 'ajaxIngreso();',
        'update' => '#listaventas',
        'class' => 'buttonS bGreen'));
        echo $this->Form->end();
        ?>
        </div>
        
        
        <div class="clear"></div>
    </div>
    <?php else:?>
    <div class="formRow">
    
        <div class="grid2"><label><a onclick="ajaxIngreso(); $('#listaventas').load('<?php echo $this->Html->url(array('controller' => 'Ventasproductos','action' => 'ajaxbuscacliente',$idventa));?>');">Cliente:</a>  <b><?php echo $cliente['Cliente']['nombre']; ?></b></label></div>
        <div class="grid2">
        <input type="button"  id="adiventa"value="ADICIONAR VENTA" class="buttonS bGreen"/>   
        </div>
        <?php 
                                            $this->Js->get('#adiventa')->event(
                                            'click',
                                            $this->Js->request(
                                                array('controller' => 'Ventasproductos','action' => 'ajaxproductos',$cliente['Cliente']['id'],$idventa),
                                                array(
                                                'async' => true,
                                                'before' => 'ajaxIngreso();',
                                                'update' => '#listaventas'))
                                            );?>
        <div class="grid2">
        <?php echo $this->Html->link('IMPRIMIR NOTA',array('action' => 'notaventa',$idventa,$idCliente),array('class' => 'buttonS bGreyish'));?>
        </div>
        <div class="grid3">
        <?php $dcp = array('Fernando' => 'FERNANDO', 'General' => 'GENERAL INTERNACIONAL SRL.'); ?>
        
          
        
        </div>
        <div class="grid3">
        <table>
        <tr>
        <td><?php echo $this->Html->link('Cancelar Venta',array('action' => 'cancelaventa',$idventa),array('class' => 'buttonS bRed'));?></td>
        <td>&nbsp;<input type="button"  id="chepres"value="PRESTAMO" class="buttonS bGold"/>&nbsp;</td>
        <td id="campoprestamo">&nbsp;
        
        <?php if($venta['Ventasproducto']['prestado'] == 1):?>
        <b class="buttonS bGreen">SI</b>
        <?php else:?>
        <b class="buttonS bRed">NO</b>
        <?php endif;?>
        </td>
        <!--
        <td>
            <div id="saldo">
            <?php if($venta['Ventasproducto']['prestado'] == 1):?>
            
            <?php else:?>
            
            <?php endif;?>
            <?php echo $this->Form->create('Ventasproducto');?>
            <?php echo $this->Form->text('saldo',array('value' => $pro['Cortestubo']['precio'],'id' => 'saldotext')); ?>
            <?php
                                            $this->Js->get('#saldotext')->event(
                                            'keyup',
                                            $this->Js->request(
                                                array('action' => 'ajaxsaldo',$idventa),
                                                array('async' => true,
                                                'update' => '#contenidosaldo',
                                                'method' => 'post','dataExpression'=>true,
                                                'data'=> $this->Js->serializeForm(array('isForm' => true,'inline' => true))))
                                            );
                                            
                    ?>    
                    <?php echo $this->Form->end();?>
            </div>
        </td>
        -->
        </tr>
        </table>
        
        <?php //echo $this->Form->checkbox('prestado',array('id' => 'chepres')); 
        
        $this->Js->get('#chepres')->event(
                                            'click',
                                            $this->Js->request(
                                                array('action' => 'ajaxprestamo',$idCliente,$idventa),
                                                array('async' => true,
                                                'update' => '#campoprestamo',
                                                'method' => 'post','dataExpression'=>true,
                                                'data'=> $this->Js->serializeForm(array('isForm' => true,'inline' => true))))
                                            );
        ?>
        
        </div>
        
        <div class="clear"></div>
    </div>
    <?php endif;?>
    <div >
    <table cellpadding="0" cellspacing="0" border="0" class="dTable" id="example">
            <thead>
                    <tr>
                        <th>Codigo</th>
                        <th>Nombre</th>
                        <th>Micaje</th>
                        <th>Alto</th>
                        <th>Peso</th>
                        <th>Sucursal</th>
                        <th>Propietario</th>
                        <th>Precio</th>
                        <th>Accion</th>
                    </tr>
                </thead>
            <tbody>
                    <?php  $i = 0; $total = 0.00; ?>
                <?php if(!empty($productos)):?>    
                <?php foreach ($productos as $pro):$i++;  ?>
                
                <tr>
                    <?php echo $this->Form->create('Cortestubo');?>
                    <td><?php echo $pro['Cortestubo']['codigo']; ?></td>
                    <td id="nombreedit<?php echo $pro['Cortestubo']['id']?>" ondblclick="$('#nombreedit<?php echo $pro['Cortestubo']['id']?>').load('<?php echo $this->Html->url(array('controller' => 'Ventasproductos','action' => 'ajaxedita',$pro['Cortestubo']['id'],true));?>');">
                    <?php if($pro['Cortestubo']['nombreaux'] != null):?>
                    <?php echo $pro['Cortestubo']['nombreaux']?>
                    <?php else:?>
                    <?php echo $pro['Tubo']['nombre']; ?>
                    <?php endif;?>
                    </td>
                    <td><?php echo $pro['Tubo']['micraje']; ?></td>
                    <td ><?php echo $pro['Cortestubo']['alto']; ?></td>
                    <td ><?php echo $pro['Cortestubo']['peso']; ?></td>
                    <td><?php echo $pro['Sucursale']['nombre']; ?></td>
                    <td>
                    <?php echo $this->Form->create('Ventasproducto');?>
        
                    <?php echo $this->Form->select('Cortestubo.propietario', $dcp, array('id' => 'seleccionapropietario'.$pro['Cortestubo']['id'],'required','class' => 'select','data-placeholder' => 'PROPIETARIO','value' => $pro['Cortestubo']['propietario'])); ?>
        <?php 
                                            $this->Js->get('#seleccionapropietario'.$pro['Cortestubo']['id'])->event(
                                            'change',
                                            $this->Js->request(
                                                array('action' => 'ajaxpropietario',$pro['Cortestubo']['id']),
                                                array('async' => true,
                                                'update' => '#',
                                                'method' => 'post',
                                                'dataExpression'=>true,
                                                'data'=> $this->Js->serializeForm(array('isForm' => true,'inline' => true))))
                                            );
                                            
                    ?>
        <?php echo $this->Form->end();?>
                    </td>
                    <td><?php echo $this->Form->text('precio',array('value' => $pro['Cortestubo']['precio'],'id' => 'id'.$pro['Cortestubo']['id'])); ?></td>
                    <td><?php echo $this->Html->link('Quitar',array('action' => 'quita',$idventa,$pro['Cortestubo']['id'],$idCliente),array('class' => 'tablectrl_small bRed tipS'));?></td>
                    <?php $total = $total + $pro['Cortestubo']['precio'];
                                            $this->Js->get('#id'.$pro['Cortestubo']['id'])->event(
                                            'keyup',
                                            $this->Js->request(
                                                array('action' => 'ajaxguarda',$pro['Cortestubo']['id'],$idventa),
                                                array('async' => true,
                                                'update' => '#total',
                                                'method' => 'post','dataExpression'=>true,
                                                'data'=> $this->Js->serializeForm(array('isForm' => true,'inline' => true))))
                                            );
                                            
                    ?>
                    <?php echo $this->Form->end();?>
                </tr>
                
            <?php endforeach; ?>
            <?php endif;?>
                </tbody>
        </table>
        <div id="total">
        <h3>TOTAL: <?php echo $total?></h3>
        </div>
    </div>
        
    </div> 
</div>
<script>
function ajaxIngreso() {
        $('#element_to_pop_up_').bPopup({
            fadeSpeed: 'slow', //can be a string ('slow'/'fast') or int
            followSpeed: 1500
        });
    }
</script> 



<?php echo $this->Js->writeBuffer(); ?>